//
//  toolManager.swift
//  groupTasks
//
//  Created by 向银泉 on 16/11/1.
//  Copyright © 2016年 向银泉. All rights reserved.
//

import UIKit
let Screen_W = UIScreen.mainScreen().bounds.size.width
let Screen_H = UIScreen.mainScreen().bounds.size.height
let UD_CurrentUserName = "UD_CurrentUserName"
let UD_LoginStatus = "UD_LoginStatus"
class toolManager: NSObject {

    static func BmobUserRegister(userName:String,passWord:String,result:(Bool,String)->Void){
        let query = BmobQuery.init(className: "UserInfo")
        query.whereKey("userName", equalTo: userName)
        query.findObjectsInBackgroundWithBlock { (allobject, error) in
            if allobject.count == 0{
                let objc = BmobObject.init(className: "UserInfo")
                objc.setObject(userName, forKey: "userName")
                objc.setObject(passWord, forKey: "passWord")
                objc.saveInBackgroundWithResultBlock({ (ret, error) in
                    if ret{result(true,"注册成功")}else{result(false,"注册失败")}
                })
            }else{result(false,"帐号已经注册")}
        }
    }
    
    static func BmobUserLogin(userName:String,passWord:String,result:(Bool,String)->Void){
        let query = BmobQuery.init(className: "UserInfo")
        query.whereKey("userName", equalTo: userName)
        query.findObjectsInBackgroundWithBlock { (allobjects, error) in
            if allobjects.count == 0{ result(false,"账号错误")}else{
                let objc = allobjects.first as! BmobObject
                let pass = objc.objectForKey("passWord")
                if pass as! String == passWord{result(true,"登录成功")
                }else{ result(false,"密码错误")}
            }
        }
    }

    
    
    

}
